<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>webview</title>
		<style>
			button {
				margin-top: 12px;
				height: 40px;
			}
		</style>
	</head>
	<body>
		<div style="padding-top: 50px;">
			我是 webview 窗口
			<button onclick="end()">结束下拉刷新</button>
			<button onclick="currentWebview()">获取当前窗口的WebviewObject对象</button>
			<button onclick="getDisplayWebview()">获取屏幕所有可视的Webview窗口</button>
			<button onclick="getWebviewById()">查找指定标识的WebviewObject窗口</button>
			<button onclick="getLaunchWebview()">获取应用首页WebviewObject窗口对象</button>
			<button onclick="getSecondWebview()">获取应用第二个首页WebviewObject窗口对象</button>
			<button onclick="getTopWebview()">获取应用显示栈顶的WebviewObject窗口对象</button>
			<button onclick="hide()">隐藏Webview窗口</button>
			<button onclick="append()">在Webview窗口中添加子窗口</button>
			<button onclick="canBack()">查询Webview窗口是否可后退</button>
			<button onclick="canForward()">查询Webview窗口是否可前进</button>
			<button onclick="checkRenderedContent()">检测Webview窗口是否渲染完成</button>
			<button onclick="getSon()">获取Webview窗口的所有子Webview窗口</button>
			<button onclick="handelClose()">关闭Webview窗口</button>
			<button onclick="draw()">截屏绘制</button>
			<button onclick="getFavoriteOptions()">获取Webview窗口的收藏参数</button>
			<button onclick="getSafeAreaInsets()">获取页面的安全区域</button>
			<button onclick="getStyle()">获取Webview窗口的样式</button>
			<button onclick="getTitle()">获取Webview窗口加载HTML页面的标题</button>
			<button onclick="overrideResourceRequest()">拦截Webview窗口的资源加载</button>
		</div>
		<script>
			let ws = null;


			function end() {
				let w = plus.webview.currentWebview();
				w.endPullToRefresh();
			}

			function currentWebview() {
				ws = plus.webview.currentWebview();
				console.log("ws=>", JSON.stringify(ws))
				console.log("当前Webview窗口：" + ws.getURL());
			}

			function getDisplayWebview() {
				let wvs = plus.webview.getDisplayWebview();
				for (var i = 0; i < wvs.length; i++) {
					console.log('Display webview ' + i + ': ' + wvs[i].getURL());
				}
			}

			function getWebviewById() {
				let h = plus.webview.getWebviewById("/hybrid/html/view.html");
				console.log("id=>", h.getURL())

			}

			function getLaunchWebview() {
				// 获取应用首页窗口对象
				let h = plus.webview.getLaunchWebview();
				console.log('应用首页Webview窗口：' + h.getURL());
			}

			function getSecondWebview() {
				let h = plus.webview.getSecondWebview();
				if (h) {
					console.log('应用第二个首页Webview窗口：' + h.getURL());
				} else {
					console.log('应用不存在第二个首页Webview窗口');
				}
			}

			function getTopWebview() {
				let h = plus.webview.getTopWebview();
				console.log('应用显示栈顶的Webview窗口：' + JSON.stringify(h));
				console.log('应用显示栈顶的Webview窗口：' + h.getURL());
			}

			function hide() {
				plus.webview.hide(plus.webview.currentWebview());
			}

			function append() {
				embed = plus.webview.create('http://m.weibo.cn/u/3196963860', '', {
					top: '46px',
					bottom: '0px'
				});
				plus.webview.currentWebview().append(embed);
			}

			function canBack() {
				ws.canBack(function(e) {
					console.log('是否可返回：' + e.canBack);
				})
			}

			function canForward() {
				ws.canForward(function(e) {
					console.log("是否可前进：" + e.canForward);
				});
			}

			function checkRenderedContent() {
				ws.checkRenderedContent({}, function(e) {
					console.log('checkRenderedContent success: ' + JSON.stringify(e));
				}, function(e) {
					console.log('checkRenderedContent error: ' + JSON.stringify(e));
				});

			}

			function getSon() {
				console.log("children")
				let list = plus.webview.currentWebview().children();
				console.log("list", list)
				for (var i = 0; i < list.length; i++) {
					console.log('Children[' + i + ']: ' + list[i].getURL());
				}

			}

			function handelClose() {
				console.log("close")
				plus.webview.currentWebview().close();
			}

			function draw() {
				let bitmap = new plus.nativeObj.Bitmap('test');
				// 将webview内容绘制到Bitmap对象中
				ws.draw(bitmap, function() {
					console.log('截屏绘制图片成功');
				}, function(e) {
					console.log('截屏绘制图片失败：' + JSON.stringify(e));
				});
			}

			function getFavoriteOptions() {
				var t = ws.getFavoriteOptions();
				alert(t ? "未设置" : JSON.stringify(t));
			}

			function getSafeAreaInsets() {
				console.log("getSafeAreaInsets")
				let h = ws.getSafeAreaInsets()
				console.log("h=>", JSON.stringify(h))
			}

			function getStyle() {
				var style = ws.getStyle();
				alert(JSON.stringify(style));
			}
			
			function getTitle(){
				let title = ws.getTitle();
				alert(title);
			}
			
			function overrideResourceRequest(){
				
			}
		</script>
	</body>
</html>
